<template>
    <div id="addAdmin">
        <main>
            <div>
                <h3>基础信息</h3>
                <el-input v-model="account" placeholder="id"></el-input>
                <el-input v-model="password" placeholder="password"></el-input>
                <el-button @click="addAdmin">新增</el-button>
            </div>
        </main>
    </div>
</template>

<script>
//引入仓库助手
import { createNamespacedHelpers } from "vuex";
//引入辅助函数
const { mapActions } = createNamespacedHelpers("admins");

export default {
    data() {
        return {
            account: "",
            password: "",
        };
    },
    methods: {
        ...mapActions(["getAdmins", "addAdmins"]),

        //新增管理员
        async addAdmin() {
            if (this.account && this.password) {
                const data = await this.addAdmins({
                    account: this.account,
                    password: this.password,
                });
                if (data.status) {
                    console.log(data);
                    this.addSuccess();
                    this.$router.push("/insuranceSystem/Administrator");
                }
            } else {
                alert("账号密码不能为空.");
            }
        },

        addSuccess() {
            this.$notify({
                title: "成功",
                message: "新增成功",
                type: "success",
            });
        },
    },
};
</script>

<style lang="scss">
#addAdmin {
    main {
        text-align: center;
        background: white;
        margin: auto;
        width: 800px;
        box-shadow: 0px 0px 4px 2px rgba($color: #000000, $alpha: 0.4);
        padding: 10px 20px;
        .el-input {
            padding: 6px 0;
        }
    }
}
</style>